Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
apollo-utilities
Advanced tools
The apollo-utilities package provides a set of utility functions for working with GraphQL data in Apollo Client. These utilities help with tasks such as parsing, transforming, and comparing GraphQL queries and results.
GraphQL Query Parsing
This feature allows you to parse a GraphQL query and extract the operation definition. The code sample demonstrates how to use the `getOperationDefinition` function to parse a query and log the operation definition.
const { getOperationDefinition } = require('apollo-utilities');
const gql = require('graphql-tag');
const query = gql`
query GetUser {
user(id: 1) {
id
name
}
}
`;
const operationDefinition = getOperationDefinition(query);
console.log(operationDefinition);
Deep Equality Check
This feature provides a deep equality check for comparing two objects. The code sample demonstrates how to use the `isEqual` function to compare two nested objects.
const { isEqual } = require('apollo-utilities');
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 2 } };
console.log(isEqual(obj1, obj2)); // true
Query Transformation
This feature allows you to transform a GraphQL query by adding `__typename` fields to it. The code sample demonstrates how to use the `addTypenameToDocument` function to transform a query.
const { addTypenameToDocument } = require('apollo-utilities');
const gql = require('graphql-tag');
const query = gql`
query GetUser {
user(id: 1) {
id
name
}
}
`;
const transformedQuery = addTypenameToDocument(query);
console.log(transformedQuery);
The graphql-tools package provides a set of utilities for building and manipulating GraphQL schemas in JavaScript. It offers functionalities such as schema stitching, schema transformation, and mock data generation. Compared to apollo-utilities, graphql-tools focuses more on schema-related tasks rather than query manipulation.
The graphql-tag package is used to parse GraphQL queries into the standard GraphQL AST format. It is often used in conjunction with Apollo Client to define queries. While graphql-tag focuses on parsing queries, apollo-utilities provides additional functionalities such as query transformation and deep equality checks.
The lodash package is a utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. While it is not specific to GraphQL, lodash offers deep equality checks and other utility functions that can be useful in a GraphQL context. Compared to apollo-utilities, lodash is more general-purpose and not tailored specifically for GraphQL.
FAQs
Utilities for working with GraphQL ASTs
The npm package apollo-utilities receives a total of 437,174 weekly downloads. As such, apollo-utilities popularity was classified as popular.
We found that apollo-utilities demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.